<?php

namespace app\api\controller\v1;


use app\admin\model\Useragentwechat;

use app\admin\model\Usershare;

use app\api\service\MessageService;
use app\common\controller\Api;


/**
 *
 */
class Userscore extends Api
{
    protected $noNeedLogin = [];
    protected $noNeedRight = ['*'];

    protected $app = null;


    public function index(){

        $user = $this->auth->getUser();

        $scoreModel = new \app\admin\model\Userscore();
        $enableScore = $scoreModel->where('uid',$user['id'])->where('is_enable',1)->sum('score');
        $disableScore = $scoreModel->where('uid',$user['id'])->where('is_enable',-1)->sum('score');

        $data = array();
        $data['enable'] = $enableScore;
        $data['disable'] = $disableScore;
        $data['total'] = $enableScore+$disableScore;


        $page = $this->request->param('page');

        $limit = 10;
        $offset = ($page - 1) * $limit;
        $list = $scoreModel->where('uid',$user['id'])->limit($offset,$limit)->select();
        foreach ($list as $key=>$val){
            $list[$key]['createtime'] = date('Y-m-d h:i:s',$val['createtime']);
        }
        $data['list'] = $list;
        $this->success('',$data);

    }
}
